package com.copyctrl.admin.service.impl;

import com.copyctrl.admin.service.AdminService;
import com.copyctrl.mapper.CampAdminMapper;
import com.copyctrl.model.CampAdmin;
import com.copyctrl.model.CampAdminExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author:JH
 * @version:1.0
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    CampAdminMapper mapper;

    @Override
    public CampAdmin login(CampAdmin admin) {
        CampAdminExample example=new CampAdminExample();
        example.createCriteria()
                .andNumberEqualTo(admin.getNumber())
                .andPasswdEqualTo(admin.getPasswd());
        List<CampAdmin> campAdmins = mapper.selectByExample(example);
        if(campAdmins.size()>0){
            admin=campAdmins.get(0);
        }
        if(admin.getIsok()==1){
            return admin;
        }
        return null;
    }

    @Override
    public int register(CampAdmin admin) {
        admin.setIsok(0);
        int insert = mapper.insert(admin);
        return insert;
    }

    @Override
    public int updateAdmin(CampAdmin admin) {
        CampAdminExample campAdminExample=new CampAdminExample();
        campAdminExample.createCriteria().andIdEqualTo(admin.getId());
        int i = mapper.updateByExampleSelective(admin, campAdminExample);
        return i;
    }
}
